<!--
 * @Author: Chenqiu
 * @Date: 2021-09-17 14:07:04
 * @LastEditors: Chenqiu
 * @LastEditTime: 2021-09-23 19:23:39
 * @Description: 
-->
<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <div class="header_top">
        <!-- 容器居中显示 -->
        <div class="wrapper">
          <div class="left">河西学院新闻网欢迎您</div>
          <div class="right">学校主页</div>
        </div>
      </div>
      <div class="header_mian">
        <div class="wrapper">
          <div class="logo" @click="toHome">
            <img src="../assets/resource/img/logo.jpg" alt />
          </div>
          <ul>
            <li :class='$route.query.name===item.name?"current":""' v-for="item in category" @click="toJump(item)" :key="item.id">{{item.name}}</li>
          </ul>
        </div>
      </div>
    </div>
    <!-- /头部 -->
  </div>
</template>
<script>
import {get} from '../utils/request'
export default {
    data(){
        return {
           category:[] 
        }
    },
    created(){
        this.loadCategory()
    },
    // 方法 事件处理程序
    methods:{
        toHome(){
          // 跳转到主页
          this.$router.push({
            path:'/home'
          })
        },
        // 跳转
        toJump(item){
            // 跳转到list页面 编程式路由导航
            // if(item.name == 'web2103'){
               this.$router.push({
                // 放跳转的路径和携带的参数
                path:'/list',
                query:item
               });
        },
        // 所有路径都要写在方法中
        // 加载所有栏目
        loadCategory(){
            let url='/index/category/findAll'
            get(url).then(res=>{
                this.category=res.data;
            })
        }
    }
}
</script>
<style lang="scss">
// 头部样式
.header {
  // margin-bottom: .8em;
  .header_top {
    background-color: #5c5675;
    color: white;

    & > .wrapper::after {
      display: block;
      content: "";
      clear: both;
    }
    .left,
    .right {
      line-height: 3em;
    }
    .left {
      float: left;
    }
    .right {
      float: right;
    }
  }
  .header_mian {
      background-color: #463f62;
    & > .wrapper {
      display: flex;
      justify-content: space-between;
      position: relative;
      ul {
        position: absolute;
        bottom: 10%;
        right: 0;
        color: rgba(175, 174, 174, 0.867);
        li {
          float: left;
          padding: 0.8em;
          cursor: pointer;
        }
        li:hover{
          background-color: #3e3758;
          color: white;
        }
        
        li.current{
          background-color: #3e3758;
          color: white;
          cursor: pointer;
        }
      }
    }
    .logo {
      img {
        height: 70px;
      }
    }
  }
}
</style>